<!--
 * @Author: ZHM zhuimin111@163.com
 * @Date: 2023-05-18 11:42:10
 * @LastEditors: ZHM zhuimin111@163.com
 * @LastEditTime: 2023-05-19 10:11:19
-->
<template>
  <div>
    <rk-dialog width="480"
      height="240"
      :title='title'
      :visible="localVisible"
      :destroyOnClose="true"
      @close="localVisible = false"
      :maskClosable="false">
      <div>
        <el-form-item>
          <el-input type="textarea"
            rows="4"
            placeholder="请输入内容"
            v-model="note" />
        </el-form-item>
      </div>
      <template #footer>
        <el-button type="primary"
          @click="ok(note)">确定
        </el-button>
        <el-button @click="localVisible=false">取消</el-button>
      </template>
    </rk-dialog>
  </div>
</template>

<script setup>
const emits = defineEmits(['update:visible']);
const note = ref("")
const props = defineProps({
  visible: {
    type: Boolean,
  },
  scoringItem: {
    type: Object,
    default: () => ({})
  },
  ok: {
    type: [Promise, Function],
    default: () => {
      return new Promise(resolve => resolve())
    }
  },
  cancel: {
    type: Promise,
    default: () => {
      return new Promise(resolve => resolve())
    }
  }
})
const title = ref('')
const localVisible = ref(props.visible)

watch(() => props.scoringItem, (val) => {
  note.value = ""
  const { opinion } = props.scoringItem.value
  if (opinion) {
    if (opinion) {
      note.value = opinion
    } else {
      note.value = ""
    }
  }
}, { deep: true, immediate: false })

watch(localVisible, (v) => {
  emits('update:visible', v)
})

watch(() => props.visible, (v) => {
  localVisible.value = v
  const { entryLev2 } = props.scoringItem.value
  title.value = (entryLev2 ? entryLev2 + "-" : "") + "评审意见"
})
</script>

<style lang="scss" scoped>
</style>
